package br.com.hsp.system.beans;

import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;

import br.com.hsp.system.repository.UserRepository;
import br.com.hsp.users.Usuario;

@ManagedBean
@SessionScoped
public class UserSessionBean {
	
	private Long tempId;
	
	public UserSessionBean() {
		System.out.println("criou");
		//Long userId= Long.parseLong("17");
		//EntityManager manager = this.getManager();
		//UserRepository repository = new UserRepository(manager);
		//this.setUserSession(repository.procura(userId));
	}
	
	private Usuario userSession;
	
	public Usuario getUserSession() {
		return userSession;
	}

	public void setUserSession(Usuario userSession) {
		this.userSession = userSession;
	}
	
	public String goProntuario(){
		Map<String, String> params = FacesContext.getCurrentInstance()
				.getExternalContext().getRequestParameterMap();
		tempId = Long.parseLong(params.get("id"));
		return "prontuarioprime";
	}
	
	public String goExame(){
		Map<String, String> params = FacesContext.getCurrentInstance()
				.getExternalContext().getRequestParameterMap();
		tempId = Long.parseLong(params.get("id"));
		return "exameprime";
	}
	
	private EntityManager getManager() {
		FacesContext fc = FacesContext.getCurrentInstance();
		ExternalContext ec = fc.getExternalContext();
		HttpServletRequest request = (HttpServletRequest) ec.getRequest();
		return (EntityManager) request.getAttribute("EntityManager");

	}

	public Long getTempId() {
		return tempId;
	}

	public void setTempId(Long tempId) {
		this.tempId = tempId;
	}
	
	
}
